package com.qf.edu.dao.impl;

import com.qf.edu.dao.GetDrugs;
import com.qf.edu.entity.Drugs;
import com.qf.edu.utils.DBUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @author:huayuzhuo
 * @email:2798866329@qq.com
 * @desc:GetDrugs接口的实现类
 * @datatime: 2022/5/31 8:47
 */
public class GetDrugsImpl implements GetDrugs {
    QueryRunner queryRunner = new QueryRunner(DBUtils.getDataSource());
    @Override
    public List<Drugs> getDrug(Drugs drugs) {
        String sql = "SELECT * FROM drugs WHERE `id` = ? or `name` = ?";
        try {
            List<Drugs> query = queryRunner.query(sql, new BeanListHandler<>(Drugs.class), drugs.getId(), drugs.getName());
            return query;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

}
